package com.example.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.dto.CouponFormDTO;
import com.example.dto.CouponIssueFormDTO;
import com.example.entity.Coupon;
import com.example.service.CouponService;
import com.example.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author circle48
 */
@RestController
@Api(tags = "平台运营端,优惠券接口")
@RequestMapping("/admin/coupon")
public class AdminCouponController {
    /**
     * 优惠券
     */
    @Resource
    private CouponService couponService;



    @PutMapping("/{id}/issue")
    @ApiOperation("发布优惠券")
    public Result issueCoupon(@PathVariable("id") Long id, @RequestBody @Validated CouponIssueFormDTO dto) {
        dto.setId(id);
        return couponService.issueCoupon(dto);
    }


    @ApiOperation("新增优惠券")
    @PostMapping
    public Result addCoupon(@RequestBody @Validated CouponFormDTO dto){
       return  couponService.addCoupon(dto);
    }


    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public Result<IPage<Coupon>> queryPage(Integer pageNum,
                                           Integer pageSize){
        return couponService.queryPage(pageNum,pageSize);
    }

    @ApiOperation("全平台优惠券")
    @GetMapping("/getAllList")
    public Result<IPage<Coupon>> getAllCouponList(Integer pageNum,
                                                 Integer pageSize,
                                                 @RequestParam(required = false) Integer couponCategory,
                                                 @RequestParam(required = false) Integer couponStatus,
                                                 @RequestParam(required = false) String couponName) {

        return couponService.getAllCouponList(pageNum, pageSize,couponCategory, couponStatus, couponName);
    }


}
